package com.example.projectmgmt.model;

import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Entity
@Data
@EntityListeners(AuditingEntityListener.class)
public class Milestone {
    @EmbeddedId
    private MilestoneId id;

    @MapsId("projectNo")
    @ManyToOne
    @JoinColumn(name = "project_no", referencedColumnName = "project_no")
    private Project project;

    @MapsId("phraseId")
    @ManyToOne
    @JoinColumns({
            @JoinColumn(name = "project_no", referencedColumnName = "project_no", insertable = false, updatable = false),
            @JoinColumn(name = "phrase_id", referencedColumnName = "phrase_id")
    })
    private Phase phase;

    @Column(name = "milestone_date", nullable = false)
    private LocalDate milestoneDate;

    @Column(name = "milestone_remarks", length = 50)
    private String milestoneRemarks;

    @CreatedDate
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;

    @LastModifiedDate
    @Column(name = "updated_at")
    private LocalDateTime updatedAt;
}